package com.zlm.search.controller;

import com.zlm.common.exception.BizCodeEnume;
import com.zlm.common.to.es.SkuEsModel;
import com.zlm.common.utils.R;
import com.zlm.search.service.ProductSaveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

/**
 * @Author: 郑
 */
@Slf4j
@RestController("/search")
public class ElasticsearchSaveController {

    @Resource
    ProductSaveService productSaveService;

    //上架商品
    @PostMapping("product")
    public R productStatUp(@RequestBody List<SkuEsModel> skuEsModels){
        boolean b = false;
        try {
            b = productSaveService.productStatUp(skuEsModels);

        } catch (IOException e) {
            log.error("ElasticsearchSaveController商品上架错误:{}",e);
            return R.error(BizCodeEnume.PRODUCT_UP_EXCEPTION.getCode(),BizCodeEnume.PRODUCT_UP_EXCEPTION.getMsg());
        }
        return b ? R.ok() : R.error(BizCodeEnume.PRODUCT_UP_EXCEPTION.getCode(),BizCodeEnume.PRODUCT_UP_EXCEPTION.getMsg());
    }

}
